<template>
    <div>
        <!-- 导航部分开始 -->
        <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">首页 </el-breadcrumb-item>>
            <el-breadcrumb-item>质量管理</el-breadcrumb-item>
            <el-breadcrumb-item>来料检验</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 导航部分结束 -->
        <!--  搜索栏开始 -->
        <el-form style="margin-top: 15px;" :inline="true" :model="queryIqc" class="demo-form-inline">
            <el-form-item label="检验单编号">
                <el-input v-model="queryIqc.iqcCode" placeholder="请输入来料检验单编号" clearable />
            </el-form-item>

            <el-form-item label="供应商名称">
                <el-input v-model="queryIqc.vendorName" placeholder="请输入供应商名称" clearable />
            </el-form-item>

            <el-form-item label="供应商批次号">
                <el-input v-model="queryIqc.vendorBatch" placeholder="请输入供应商批次号" clearable />
            </el-form-item>

            <el-form-item label="产品物料编码">
                <el-input v-model="queryIqc.itemCode" placeholder="请输入产品物料编码" clearable />
            </el-form-item>

            <el-form-item label="产品物料名称">
                <el-input v-model="queryIqc.itemName" placeholder="请输入产品物料名称" clearable />
            </el-form-item>

            <el-form-item label="检测结果">
                <el-select v-model="queryIqc.checkResult" placeholder="请选择检测结果">
                    <el-option label="检验通过" value="检验通过" />
                    <el-option label="检验不通过" value="检验不通过" />
                </el-select>
            </el-form-item>

            <el-form-item label="来料日期">
                <el-date-picker v-model="queryIqc.reciveDate" type="date" format="YYYY-MM-DD" placeholder="请选择来料日期" />
            </el-form-item>

            <el-form-item label="检测日期">
                <el-date-picker v-model="queryIqc.inspectDate" type="date" format="YYYY-MM-DD" placeholder="请选择检测日期" />
            </el-form-item>

            <el-form-item label="检测人员">
                <el-input v-model="queryIqc.inspecor" placeholder="请输入检测人员" clearable />
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="loadiqc">搜索</el-button>
                <el-button @click="resettingiqc">重置</el-button>

            </el-form-item>
        </el-form>
        <!--  搜索栏结束 -->
        <!-- 工具栏开始 -->
        <div class="flex">
            <el-button title="新增" @click="this.addIqcDialogVisible = true" type="primary"><el-icon>
                    <Plus />
                </el-icon>新增</el-button>
            <el-button color="#b3e19d" @click="handlerEditIqc" title="修改" type="primary"><el-icon>
                    <EditPen />
                </el-icon>修改</el-button>

            <el-button color="#f89898" @click="handlerDeleteIqc" title="删除" type="primary"><el-icon>
                    <Delete />
                </el-icon>删除</el-button>
            <!--工具栏结束 -->
        </div>
        <!-- 表格 开始 -->
        <el-table ref="iqcTable" :data="iqc" max-height="800px" :stripe="true" :border="true"
            style="width: 200%;margin-top: 10px;">
            <el-table-column type="selection" />

            <el-table-column width="150" align="center" label="来料检验单编号" property="iqcCode">
                <template #default="scope">
                    <el-link type="success" @click="showIqcData(scope.row.iqcId)">
                        {{ scope.row.iqcCode }}
                    </el-link>
                </template>
            </el-table-column>
            <el-table-column width="150" align="center" label="来料检验单名称" property="iqcName" />
            <el-table-column width="150" align="center" label="供应商简称" property="vendorName" />
            <el-table-column width="150" align="center" label="供应商批次号" property="vendorBatch" />
            <el-table-column width="150" align="center" label="产品物料编码" property="itemCode" />
            <el-table-column width="150" align="center" label="产品物料名称" property="itemName" />
            <el-table-column width="150" align="center" label="接受数量" property="quantityRecived" />
            <el-table-column width="150" align="center" label="检验数量" property="quantityCheck" />
            <el-table-column width="150" align="center" label="不合格数" property="quantityUnqualified" />
            <el-table-column width="150" align="center" label="检验结果" property="checkResult" />
            <el-table-column width="150" align="center" label="来料日期" property="reciveDate" />
            <el-table-column width="150" align="center" label="检验日期" property="inspectDate" />
            <el-table-column width="150" align="center" label="检验人员" property="inspecor" />
            <el-table-column width="150" align="center" label="单据状态" property="status" />

            <el-table-column width="200" align="center" label="操作">
                <template #default="scope">
                    <div v-if="scope.row.status == '草稿' || scope.row.status != '已完成'">
                        <el-button size="small" type="primary" @click="handleEdit(scope.row)">修改</el-button>
                        <el-popconfirm confirm-button-text="是" cancel-button-text="点错了" @confirm="handleDelete(scope.row)"
                            title="您是否要删除这行数据">
                            <template #reference>
                                <el-button size="small" type="danger">删除</el-button>
                            </template>
                        </el-popconfirm>
                    </div>

                </template>
            </el-table-column>
        </el-table>
        <!-- 表格 结束 -->
        <!-- 分页栏开始 -->
        <el-pagination style="margin-top: 15px;" :page-size="iqcLimit" :pager-count="iqcMaxPage"
            @current-change="changePageIqc" background layout="prev, pager, next" :total="iqcTotal" />
        <!-- 分页栏结束 -->

        <!-- 完成按钮的弹窗 -->
        <el-dialog v-model="FinishDialogVisible" title="系统提示" width="30%" draggable>
            <span><el-icon>
                    <WarnTriangleFilled />
                </el-icon>是否完成来料检验单编制?[完成后将不能更改]</span>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="FinishCancellation">取消</el-button>
                    <el-button type="primary" @click="Finish()">
                        确定
                    </el-button>
                </span>
            </template>
        </el-dialog>
        <!-- 添加检测的弹窗窗体开始-->
        <el-dialog v-model="addIqcDialogVisible" title="添加检验名单" width="65%" align-center>
            <!-- 添加检测的表单 -->
            <el-form label-width="100px" :model="newIqc" style="max-width: 900px">

                <el-row>
                    <el-col :span="12">
                        <el-form-item label="检验编号">
                            <el-input v-model="newIqc.iqcCode" />
                            <el-switch @change="autoGenIqcCode" v-model="autoIqcCode" class="ml-2"
                                style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949" />
                            自动生成
                        </el-form-item>

                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="检验单名称">
                            <el-input v-model="newIqc.iqcName" />
                        </el-form-item>

                    </el-col>
                </el-row>
                <el-divider>物料与供应商</el-divider>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="产品物料编码">
                            <el-input v-model="newIqc.itemCode" disabled>

                                <template #append>
                                    <el-button @click="this.searchProduct = true" type="primary"><el-icon>
                                            <Search />
                                        </el-icon></el-button>
                                </template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="产品物料名称">
                            <el-input v-model="newIqc.itemName" disabled placeholder="请输入检测项名称" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="单位">
                            <el-input v-model="newIqc.unitOfMeasure" />
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span="8">
                        <el-form-item label="供应商编码">
                            <el-input v-model="newIqc.vendorCode" disabled>

                                <template #append>
                                    <el-button @click="this.searchVendor = true" type="primary"><el-icon>
                                            <Search />
                                        </el-icon></el-button>
                                </template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="供应商简称">
                            <el-input v-model="newIqc.vendorName" disabled placeholder="请输入检测项名称" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="供应商批次号">
                            <el-input v-model="newIqc.vendorBatch" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-divider>检测情况</el-divider>
                <el-row>
                    <el-col :span="8">

                        <el-form-item label="本次接收数量">
                            <el-input-number v-model="newIqc.quantityRecived" :min="0" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="本次检测数量">
                            <el-input v-model="newIqc.quantityCheck" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="不合格数量">
                            <el-input-number v-model="newIqc.quantityUnqualified" :min="0" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="来料日期">
                            <el-date-picker v-model="newIqc.reciveDate" value-format="YYYY/MM/DD" type="date"
                                placeholder="请选择来料日期" />
                        </el-form-item>

                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="检测日期">
                            <el-date-picker v-model="newIqc.inspectDate" value-format="YYYY/MM/DD" type="date"
                                placeholder="请选择检测日期" />
                        </el-form-item>

                    </el-col>
                    <el-col :span="8">

                        <el-form-item label="检测结果">
                            <el-select v-model="newIqc.checkResult" placeholder="请选择检测结果">
                                <el-option label="检验通过" value="检验通过" />
                                <el-option label="检验不通过" value="检验不通过" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>

                    <el-col :span="12">
                        <el-form-item label="检测人员">
                            <el-input v-model="newIqc.inspecor" />
                        </el-form-item>

                    </el-col>
                </el-row>


            </el-form>

            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="cancelAddIqc">取消</el-button>
                    <el-button type="primary" @click="doAddIndexIqc">
                        提交
                    </el-button>
                </span>
            </template>
        </el-dialog>
        <!-- 添加的弹窗窗体结束-->
        <!-- 查看信息弹窗窗体开始-->
        <el-dialog v-model="DialogVisibles" title="查看来料信息" width="65%" align-center>
            <!-- 查看的表单 -->
            <el-form label-width="100px" :model="lookIqc" style="max-width: 900px">

                <el-row>
                    <el-col :span="12">

                        <el-form-item label="检验编号">
                            <el-input v-model="lookIqc.iqcCode" />
                        </el-form-item>

                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="检验单名称">
                            <el-input v-model="lookIqc.iqcName" />
                        </el-form-item>

                    </el-col>
                </el-row>
                <el-divider>物料与供应商</el-divider>

                <el-row>
                    <el-col :span="8">
                        <el-form-item label="产品物料编码">
                            <el-input v-model="lookIqc.itemCode">
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="产品物料名称">
                            <el-input v-model="lookIqc.itemName" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="单位">
                            <el-input v-model="lookIqc.unitOfMeasure" />
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span="8">
                        <el-form-item label="供应商编码">
                            <el-input v-model="lookIqc.vendorCode" disabled>


                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="供应商简称">
                            <el-input v-model="lookIqc.vendorName" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="供应商批次号">
                            <el-input v-model="lookIqc.vendorBatch" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-divider>检测情况</el-divider>
                <el-row>
                    <el-col :span="8">

                        <el-form-item label="本次接收数量">
                            <el-input-number v-model="newIqc.quantityRecived" :min="0" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="本次检测数量">
                            <el-input v-model="lookIqc.quantityCheck" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="不合格数量">
                            <el-input-number v-model="lookIqc.quantityUnqualified" :min="0" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="来料日期">
                            <el-date-picker v-model="lookIqc.reciveDate" value-format="YYYY/MM/DD" type="date"
                                placeholder="请选择来料日期" />
                        </el-form-item>

                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="检测日期">
                            <el-date-picker v-model="lookIqc.inspectDate" value-format="YYYY/MM/DD" type="date"
                                placeholder="请选择检测日期" />
                        </el-form-item>

                    </el-col>
                    <el-col :span="8">

                        <el-form-item label="检测结果">
                            <el-select v-model="lookIqc.checkResult" placeholder="请选择检测结果">
                                <el-option label="检验通过" value="检验通过" />
                                <el-option label="检验不通过" value="检验不通过" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>

            </el-form>
            <template #footer>
                <div sty le="flex: auto">
                    <el-button @click="cancelLookIqcEdit">取消</el-button>
                    <el-button type="primary" @click="doLookIqcReturn">返回</el-button>
                </div>
            </template>
        </el-dialog>
        <!-- 查看信息弹窗窗体结束-->
        <!-- 编辑弹窗开始 -->
        <el-dialog v-model="iqcEditDrawer" title="编辑来料产品" width="65%" align-center>
            <!-- 编辑表单开始 -->
            <el-form label-width="100px" :model="updataIqc" style="max-width: 900px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="检验编号">
                            <el-input v-model="updataIqc.iqcCode" />
                            <el-switch @change="autoGenIqcCode" v-model="autoIqcCode" class="ml-2"
                                style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949" />
                            自动生成
                        </el-form-item>

                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="检验单名称">
                            <el-input v-model="updataIqc.iqcName" />
                        </el-form-item>

                    </el-col>
                </el-row>
                <el-divider>物料与供应商</el-divider>
                <el-row>
                    <el-col :span="8">

                        <el-form-item label="产品物料编码">
                            <el-input v-model="updataIqc.itemCode" disabled>
                                <template #append>
                                    <el-button @click="this.searchProduct = true" type="primary"><el-icon>
                                            <Search />
                                        </el-icon></el-button>
                                </template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="产品物料名称">
                            <el-input v-model="updataIqc.itemName" disabled placeholder="请输入检测项名称" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="单位">
                            <el-input v-model="updataIqc.unitOfMeasure" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="供应商编码">
                            <el-input v-model="updataIqc.vendorCode" disabled>

                                <template #append>
                                    <el-button @click="this.searchVendor = true" type="primary"><el-icon>
                                            <Search />
                                        </el-icon></el-button>
                                </template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="供应商简称">
                            <el-input v-model="updataIqc.vendorName" disabled placeholder="请输入检测项名称" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="供应商批次号">
                            <el-input v-model="updataIqc.vendorBatch" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-divider>检测情况</el-divider>
                <el-row>
                    <el-col :span="8">

                        <el-form-item label="本次接收数量">
                            <el-input-number v-model="updataIqc.quantityRecived" :min="0" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="本次检测数量">
                            <el-input v-model="updataIqc.quantityCheck" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="不合格数量">
                            <el-input-number v-model="updataIqc.quantityUnqualified" :min="0" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="来料日期">
                            <el-date-picker v-model="updataIqc.reciveDate" value-format="YYYY/MM/DD" type="date"
                                placeholder="请选择来料日期" />
                        </el-form-item>

                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="检测日期">
                            <el-date-picker v-model="updataIqc.inspectDate" value-format="YYYY/MM/DD" type="date"
                                placeholder="请选择检测日期" />
                        </el-form-item>

                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="检测结果">
                            <el-select v-model="updataIqc.checkResult" placeholder="请选择检测结果">
                                <el-option label="检验通过" value="检验通过" />
                                <el-option label="检验不通过" value="检验不通过" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>

            <template #footer>
                <div v-if="updataIqc.status == '草稿' || updataIqc.status != '已完成'">
                    <el-button @click="cancelEditsProduct">取消</el-button>
                    <el-button type="success" @click="FinishDialogVisibleupdate = true">完成</el-button>
                    <el-button type="primary" @click="doProductEdits">提交</el-button>
                </div>
                <div v-if="updataIqc.status == '已完成'">
                    <el-button size="small" type="info" @click="cancelEditsProduct">取消</el-button>
                    <el-button size="small" type="success" @click="cancelEditsProduct">返回</el-button>
                </div>
            </template>
        </el-dialog>

        <!-- 编辑弹窗结束 -->
        <!-- 物料产品搜索事件 -->
        <!-- 搜索物料的弹窗窗体开始 -->
        <el-dialog v-model="searchProduct" title="物料选择" width="80%" align-center>
            <el-container>
                <el-aside width="200px">
                    <!-- 分类树 -->
                    <el-tree ref="tree" :data="itemTypes" :expand-on-click-node="false" node-key="itemTypeId"
                        :props="defaultProps" @node-click="optionItemByTree" default-expand-all style=" font-size: 15px;" />
                </el-aside>
                <el-main>
                    <!-- 搜索栏开始 -->
                    <el-form :inline="true" :model="search" class="demo-form-inline">
                        <el-form-item label="物料编码">
                            <el-input v-model="search.itemCode" placeholder="请输入物料编码" />
                        </el-form-item>
                        <el-form-item label="物料名称">
                            <el-input v-model="search.itemName" placeholder="请输入物料名称" />
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="loadItem"><el-icon>
                                    <search />
                                </el-icon>搜索</el-button>
                            <el-button @click="handleReset"><el-icon>
                                    <refresh />
                                </el-icon>重置</el-button>
                        </el-form-item>
                    </el-form>
                    <!-- 搜索栏结束 -->

                    <!-- 表格 开始 -->
                    <el-table ref="itemTable" :data="items" max-height="80%" style="margin-top: 10px;">
                        <el-table-column type="selection" width="55" />
                        <el-table-column label="物料编码" property="itemCode" width="90" />
                        <el-table-column label="物料名称" property="itemName" width="120" />
                        <el-table-column label="规格型号" property="specification" width="100" />
                        <el-table-column label="单位" property="unitOfMeasure" width="70" />
                        <el-table-column label="物料/产品" property="itemOrProduct" width="110" />
                        <el-table-column label="所属分类" property="itemTypeName" width="100" />
                        <el-table-column label="创建时间" :formatter="timeFormatter" property="createTimeMillis" />

                    </el-table>
                    <!-- 表格 结束 -->

                </el-main>
            </el-container>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="cancelUpdate">取消</el-button>
                    <el-button type="primary" @click="doUpdate">提交</el-button>
                </span>
            </template>


        </el-dialog>
        <!-- 搜索物料的弹窗窗体结束 -->
        <!-- 搜索供应商弹窗开始-->
        <el-dialog v-model="searchVendor" title="供应商选择" width="80%" align-center>
            <!-- 搜索栏开始 -->
            <el-form :inline="true" :model="searchVen" class="demo-form-inline">
                <el-form-item label="供应商编码">
                    <el-input v-model="searchVen.vendorCode" placeholder="请输入供应商编码" />
                </el-form-item>
                <el-form-item label="供应商名称">
                    <el-input v-model="searchVen.vendorName" placeholder="请输入供应商名称" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="loadVendor"><el-icon>
                            <search />
                        </el-icon>搜索</el-button>
                    <el-button @click="handleReset"><el-icon>
                            <refresh />
                        </el-icon>重置</el-button>
                </el-form-item>
            </el-form>
            <!-- 搜索栏结束 -->
            <!-- 表格 开始 -->
            <el-table ref="table" :data="vendors" max-height="800px" style="margin-top: 10px;">
                <el-table-column type="selection" width="55" />
                <el-table-column label="供应商编码" prop="vendorCode" />
                <el-table-column label="供应商名称" property="vendorName" />
                <el-table-column label="供应商等级" property="vendorLevel" />
                <el-table-column label="供应商评分" property="vendorScore" />
                <el-table-column label="供应商地点" property="address" />
                <el-table-column label="创建时间" :formatter="timeFormatter" property="createTimeMillis" />
            </el-table>
            <!-- 表格 结束 -->
            <!-- 分页栏开始 -->
            <el-pagination style="margin-top: 15px;" :page-size="limit" :pager-count="maxPageNum"
                @current-change="changePage" background layout="prev, pager, next" :total="total" />
            <!-- 分页栏结束 -->
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="cancelUpdateVender">取消</el-button>
                    <el-button type="primary" @click="doUpdateVender">提交</el-button>
                </span>
            </template>
        </el-dialog>
        <!-- 搜索供应商弹窗结束-->
        <!-- 编辑完成按钮的弹窗 -->
        <el-dialog v-model="FinishDialogVisibleupdate" title="系统提示" width="30%" draggable>
            <span><el-icon>
                    <WarnTriangleFilled />
                </el-icon>确认完成来料检验单编制？[完成后将不能修改]</span>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="CanceDialogVisible()">取消</el-button>
                    <el-button type="primary" @click="updateFinish()">
                        确定
                    </el-button>
                </span>
            </template>
        </el-dialog>
        <!--编辑过程检验数据结束 -->






    </div>
</template>
<script>
import iqcRequst from '../../../api/iqc-api.js';
import genIdRequst from '../../../api/qcGenId-api.js';
import itemTypeRequest from "../../../api/md-item-type";
import mdItemRequest from "../../../api/md-item";
import tools from '../../../util/tools';
import mdVendorRequest from '../../../api/md-vendor';



export default {
    data() {
        return {
            queryIqc: {},//搜索数据对象
            addIqcDialogVisible: false,//工具栏新增按钮窗口
            iqc: [],//表格对象
            newIqc: {},//封装增加窗口

            iqcCurrPage: 1, // 字典分页的当前页码
            iqcLimit: 10, // 字典分页的每页大小
            iqcTotal: 0, // 字典列表的总条数
            iqcMaxPage: 1,// 字典列表的最大页码
            autoIqcCode: false,//新增自动生成按钮
            newIqc: {
                iqcCode: undefined
            },
            // ====物料产品事件
            searchProduct: false,//产品物料搜索按钮
            search: {},//搜索物料对象
            itemTypes: [],// 分类菜单的所有数据
            defaultProps: {
                children: 'children',// 孩子节点集合的属性名
                label: 'itemTypeName',// 对应的文本的属性名
            },
            // 分页数据
            page: 1, // 页数
            limit: 10, // 每页条数
            total: 0, // 总条数
            maxPageNum: 1, // 最大页数
            items: [], // 查询到的数据
            //==========供应商事件
            searchVendor: false,//供应商搜索按钮
            searchVen: {},//供应商搜索事件
            // 分页数据
            page: 1, // 页数
            limit: 10, // 每页条数
            total: 0, // 总条数
            maxPageNum: 1, // 最大页数
            vendors: [], // 查询到的供应商数据

            DialogVisibles: false,//查看信息弹窗
            lookIqc: {},//封装查看信息
            iqcEditDrawer: false,//编辑窗口
            updataIqc: {},//封装编辑表单
            FinishDialogVisibleupdate: false,//编辑完成按钮属性
            iqcEditDrawer: false,//编辑窗口

        }
    },
    methods: {
        //编辑完成取消按钮
        CanceDialogVisible() {
            this.FinishDialogVisibleupdate = false;

        },
        //编辑确定完成按钮
        updateFinish() {
            this.updataIqc.status = "已完成";
            iqcRequst.edit(this.updataIqc, res => {
                // 这里的res就是我们的后端返回的perResult对象
                if (res.code == '200') {
                    this.$message({
                        message: '已完成',
                        type: 'success'
                    });
                    //关闭窗体
                    this.FinishDialogVisibleupdate = false;
                    this.iqcEditDrawer = false;
                    // 重新加载数据
                    this.loadiqc();
                    // 将newDefect制空
                    this.updataIqc = {};

                } else {
                    this.$message({
                        message: '添加失败',
                        type: 'error',
                    });
                }
            });

        },




        //行删除按钮
        handleDelete(row) {
            iqcRequst.delete(row.iqcId, res => {
                if (res.code == 200) {
                    this.$message({
                        type: "success",
                        message: "删除成功"
                    });
                    this.loadiqc();//重新加载数据
                } else {
                    this.$message({
                        type: "error",
                        message: "删除失败"
                    });
                }
            })

        },
        //编辑提交按钮
        doProductEdits() {

            iqcRequst.edit(this.updataIqc, res => {
                // 这里的res就是我们的后端返回的perResult对象
                if (res.code == '200') {
                    this.$message({
                        message: '编辑成功',
                        type: 'success'
                    });
                    //关闭窗体
                    this.iqcEditDrawer = false;
                    // 重新加载数据
                    this.loadiqc();
                    // 将editIndex制空
                    this.updataIqc = {};
                } else if (res.code == '300') {
                    this.$message({
                        message: '检测名称重复',
                        type: 'warning',
                    });
                } else {
                    this.$message({
                        message: '编辑失败',
                        type: 'error',
                    });
                }
            });

        },
        //编辑取消按钮
        cancelEditsProduct() {
            //关闭窗体
            this.iqcEditDrawer = false;
        },
        //行编辑按钮
        handleEdit(row) {

            // 通过id加载要编辑的用户信息
            iqcRequst.get(row.iqcId, res => {
                // 将查询的用户信息设置到editUser中
                this.updataIqc = res.data;
                // 显示抽屉弹窗
                this.iqcEditDrawer = true;

            });

        },


        //点击编号查看信息按钮
        showIqcData(iqcId) {
            iqcRequst.get(iqcId, res => {
                // 将查询的用户信息设置到editUser中
                this.lookIqc = res.data;
                this.loadiqc();
                this.DialogVisibles = true;
            });
        },
        //取消
        cancelLookIqcEdit() {
            this.DialogVisibles = false;//关闭窗体
        },

        //返回
        doLookIqcReturn() {
            this.DialogVisibles = false;//关闭窗体
        },

        //新增自动生成编号
        autoGenIqcCode(val) {
            if (val) {
                genIdRequst.genIqcCode(res => {
                    this.newIqc.iqcCode = res.data;
                });

            };


        },
        //新增取消按钮
        cancelAddIqc() {
            // 将newDefect制空
            this.newIqc = {};
            // 关闭窗体
            this.addIqcDialogVisible = false;
        },
        //新增提交按钮
        doAddIndexIqc() {
            this.autoIndexCode = false;
            this.newIqc.status = "草稿";
            console.log(this.newIqc);
            iqcRequst.save(this.newIqc, res => {
                // 这里的res就是我们的后端返回的perResult对象
                if (res.code == '200') {
                    this.$message({
                        message: '添加成功',
                        type: 'success'
                    });
                    //关闭窗体
                    this.addIqcDialogVisible = false;
                    // 重新加载数据
                    this.loadiqc();
                    // 将newDefect制空
                    this.newIqc = {};

                } else if (res.code == '300') {
                    this.$message({
                        message: '描述重复',
                        type: 'warning',
                    });
                } else {
                    this.$message({
                        message: '添加失败',
                        type: 'error',
                    });
                }
            });

        },

        //工具栏删除按钮
        handlerDeleteIqc() {
            // 获取表格对象
            let table = this.$refs.iqcTable;
            // 通过API获取被选中的数据 
            let selectionRows = table.getSelectionRows();
            if (selectionRows == undefined || selectionRows.length == 0) {
                this.$message({
                    type: "info",
                    message: "您没有选中任何行"
                });
            }
            // console.log(selectionRows);
            // 可以进行批量改删除了
            //批量删除的第一件事
            //生产一个要删除的userId的数组
            let iqcIds = [];

            //forEach 指的是从数组每一次取值是会赋值给user
            selectionRows.forEach(iqc => {
                // console.log(defect);
                iqcIds.push(iqc.iqcId);
            });
            console.log(iqcIds);
            //调用API进行删除
            iqcRequst.deletes(iqcIds, res => {
                this.$message({
                    type: "success",
                    message: "成功删除" + res.msg + "条数据"
                });
                this.loadiqc();//重新加载数据
            });

        },
        //工具栏修改按钮
        handlerEditIqc() {
            // 获取表格对象
            let table = this.$refs.iqcTable;
            // 通过API获取被选中的数据 
            let selectionRows = table.getSelectionRows();
            if (selectionRows == undefined || selectionRows.length == 0) {
                this.$message({
                    type: "info",
                    message: "您没有选中任何行"
                });
            }

            // 获取第一行数据
            let row = selectionRows[0];
            // 调用行编辑事件
            this.handleEdit(row);





        },
        //===========新增搜索=================================
        //搜索供应商弹窗取消按钮
        cancelUpdateVender() {
            this.searchVendor = false;//关闭窗体

            this.loadVendor();

        },
        //搜索供应商提交按钮  
        doUpdateVender() {
            let table = this.$refs.table; // 获取表格对象
            let rows = table.getSelectionRows(); // 通过API获取被选中的数据
            this.newIqc.vendorCode = rows[0].vendorCode;
            this.newIqc.vendorName = rows[0].vendorName;

            this.updataIqc.vendorCode = rows[0].vendorCode;
            this.updataIqc.vendorName = rows[0].vendorName;

            console.log(this.updataIqc.vendorCode);
            this.searchVendor = false;
            //重新加载数据
            this.loadVendor();

        },

        /**
         * 搜索栏重置按钮事件
         */
        handleReset() {
            this.search = {}; // 搜索对象置空
            this.loadVendor(); // 重新加载数据
        },
        /**
         * 初始化时间
         */
        timeFormatter(row, column, cellValue) {
            return tools.timeMillisToString(cellValue);
        },

        /**
         * 加载表格数据
         */
        loadVendor() {
            mdVendorRequest.list(this.page, this.limit, this.search, res => {
                this.vendors = res.data.list;
                this.total = res.data.total;
                this.maxPageNum = res.data.pages;
            })
        },

        //搜索物料弹窗取消按钮
        cancelUpdate() {
            this.searchProduct = false;//关闭窗体

        },

        //搜索物料提交按钮
        doUpdate() {
            let table = this.$refs.itemTable; // 获取新增的表格对象
            let rows = table.getSelectionRows(); // 通过API获取被选中的数据
            this.newIqc.itemCode = rows[0].itemCode;
            this.newIqc.itemName = rows[0].itemName;
            this.newIqc.unitOfMeasure = rows[0].unitOfMeasure;
            console.log(this.newIqc.intemCode);

            this.updataIqc.itemCode = rows[0].itemCode;
            this.updataIqc.itemName = rows[0].itemName;
            this.updataIqc.unitMeasure = rows[0].unitOfMeasure;
            console.log(this.updataIqc.intemCode);

            this.searchProduct = false;
            //重新加载数据
            this.loadItemType();
            this.loadItem();

        },
        // 点击分页事件
        changePage(val) {
            this.page = val;
            this.loadItem();
            this.page = val;
            this.loadVendor();
        },
        //新增按钮事件
        handleAdd() {
            this.addItemDialogVisible = true;
            mdItemRequest.getByAncestors(res => {
                this.itemType = res.data;
            })
        },
        //条件搜索重置按钮事件
        handleReset() {
            this.search = {};
            this.loadItem();
        },
        //初始化时间
        timeFormatter(row, column, cellValue) {
            return tools.timeMillisToString(cellValue);
        },
        //加载搜索物料数据
        loadItem() {
            mdItemRequest.list(this.page, this.limit, this.search, res => {
                this.items = res.data.list;
                this.total = res.data.total;
                this.maxPageNum = res.data.pages;
            })
        },
        //加载搜索树物料信息
        loadItemType(isReal) {
            if (this.itemTypes == undefined || this.itemTypes.length == 0 || isReal) {
                itemTypeRequest.listTree(res => {
                    this.itemTypes = res.data;
                })
            }
        },


        //=========新增搜索结束====================================
        //分页
        changePageIqc(value) {
            this.iqcCurrPage = value;
            this.loadiqc();
        },
        //加载数据信息
        loadiqc() {
            iqcRequst.list(this.iqcCurrPage, this.iqcLimit,
                this.queryIqc, res => {
                    // 设置数据
                    this.iqc = res.data.list;
                    this.iqcTotal = res.data.total;
                    this.iqcMaxPage = res.data.pages;

                });

        },
        //重置操作
        resettingiqc() {
            // 制空
            this.queryIqc = {};
            this.loadiqc();

        },


    },
    mounted() {
        this.loadiqc();//加载数据
        this.loadItem();
        this.loadItemType();
        this.loadVendor();


    }

}




</script>